package com.macro.mall.portal.service.impl;

import com.macro.mall.mapper.BmsTourismProjectActivitiesPicMapper;
import com.macro.mall.model.BmsTourismProjectActivitiesPic;
import com.macro.mall.model.BmsTourismProjectActivitiesPicExample;
import com.macro.mall.portal.service.BmsTourismProjectActivitiesPicService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class BmsTourismProjectActivitiesPicServiceImpl implements BmsTourismProjectActivitiesPicService {

    @Autowired
    private BmsTourismProjectActivitiesPicMapper bmsTourismProjectActivitiesPicMapper;


    @Override
    public void deleteByActivitiesId(Long tourismProjectActivitiesId) {
        BmsTourismProjectActivitiesPicExample example = new BmsTourismProjectActivitiesPicExample();
        BmsTourismProjectActivitiesPicExample.Criteria criteria = example.createCriteria();
        criteria.andTourismProjectActivitiesIdEqualTo(tourismProjectActivitiesId);
        bmsTourismProjectActivitiesPicMapper.deleteByExample(example);
    }

    @Override
    public String findCoverPicByActivitiesId(Long tourismProjectActivitiesId) {
        BmsTourismProjectActivitiesPicExample example = new BmsTourismProjectActivitiesPicExample();
        BmsTourismProjectActivitiesPicExample.Criteria criteria = example.createCriteria();
        criteria.andTourismProjectActivitiesIdEqualTo(tourismProjectActivitiesId);
        criteria.andIsCoverEqualTo((byte) 1);
        List<BmsTourismProjectActivitiesPic> bmsTourismProjectActivitiesPics = bmsTourismProjectActivitiesPicMapper.selectByExample(example);
        if (CollectionUtils.isNotEmpty(bmsTourismProjectActivitiesPics)) {
            return bmsTourismProjectActivitiesPics.get(0).getPic();
        }
        return null;
    }

    @Override
    public List<String> findPicListByActivitiesId(Long tourismProjectActivitiesId) {
        BmsTourismProjectActivitiesPicExample example = new BmsTourismProjectActivitiesPicExample();
        BmsTourismProjectActivitiesPicExample.Criteria criteria = example.createCriteria();
        criteria.andTourismProjectActivitiesIdEqualTo(tourismProjectActivitiesId);
        criteria.andIsCoverEqualTo((byte) 0);
        List<BmsTourismProjectActivitiesPic> bmsTourismProjectActivitiesPics = bmsTourismProjectActivitiesPicMapper.selectByExample(example);
        if (CollectionUtils.isNotEmpty(bmsTourismProjectActivitiesPics)) {
            return bmsTourismProjectActivitiesPics.stream().map(BmsTourismProjectActivitiesPic::getPic).collect(Collectors.toList());
        }
        return null;
    }
}
